-
Notifications
You must be signed in to change notification settings - Fork 11
feature: add test sandbox mode #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
that emits sync events from updates within a sandboxed transaction
|
I've followed the instructions. I get: My config :phoenix_sync,
env: :test,
mode: :sandbox,
repo: Burn.RepoMy test_helper.exs contains: ExUnit.start()
Ecto.Adapters.SQL.Sandbox.mode(Burn.Repo, :manual)My data case: defmodule Burn.DataCase do
use ExUnit.CaseTemplate
using do
quote do
alias Burn.Repo
import Ecto
import Ecto.Changeset
import Ecto.Query
import Burn.DataCase
end
end
setup tags do
Burn.DataCase.setup_sandbox(tags)
:ok
end
@doc """
Sets up the sandbox based on the test tags.
"""
def setup_sandbox(tags) do
pid = Ecto.Adapters.SQL.Sandbox.start_owner!(Burn.Repo, shared: not tags[:async])
on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end)
# Start sandbox replication stack.
Phoenix.Sync.Sandbox.start!(Burn.Repo, pid, shared: not tags[:async])
end
endI guess I need to start the |
No, it should be started as part of the application. I'm sure I hit this exact problem but damned if I can remember the cause. I fixed it but obviously failed to capture the solution in the docs. Might be your version of electric... Do you have electric as a dep? That would prevent the sandbox supervisor from starting |
|
Pulled latest branch and avoided starting shape subscriptions before sandbox and my tests run. Next issue is that my code writes a map to a JSONB field and this raises a |
|
On the "don't start shape subscriptions until the sandbox is ready" front, this is my hacked application.ex: defmodule Burn.Application do
use Application
@impl true
def start(_type, _args) do
children = [
BurnWeb.Telemetry,
Burn.Repo,
{DNSCluster, query: Application.get_env(:burn, :dns_cluster_query) || :ignore},
{Phoenix.PubSub, name: Burn.PubSub},
{Finch, name: Burn.Finch},
{Registry, keys: :unique, name: Burn.Agents},
] ++ sync_spawning_children(Mix.env()) ++ [
{BurnWeb.Endpoint, phoenix_sync: Phoenix.Sync.plug_opts()}
]
opts = [strategy: :one_for_one, name: Burn.Supervisor]
Supervisor.start_link(children, opts)
end
defp sync_spawning_children(:test), do: []
defp sync_spawning_children(_), do: [Burn.Agents.Supervisor]
@impl true
def config_change(changed, _new, removed) do
BurnWeb.Endpoint.config_change(changed, removed)
:ok
end
endEyeballing it, I wonder if there could be an API like: defmodule Burn.Application do
use Application
@impl true
def start(_type, _args) do
children = [
BurnWeb.Telemetry,
Burn.Repo,
{DNSCluster, query: Application.get_env(:burn, :dns_cluster_query) || :ignore},
{Phoenix.PubSub, name: Burn.PubSub},
{Finch, name: Burn.Finch},
{Registry, keys: :unique, name: Burn.Agents},
{Phoenix.Sync.SandboxAwareSupervisor, children: [
Burn.Agents.Supervisor
]}
{BurnWeb.Endpoint, phoenix_sync: Phoenix.Sync.plug_opts()}
]
opts = [strategy: :one_for_one, name: Burn.Supervisor]
Supervisor.start_link(children, opts)
end
@impl true
def config_change(changed, _new, removed) do
BurnWeb.Endpoint.config_change(changed, removed)
:ok
end
endI.e.: just nest processes that need to be sandbox aware inside |
|
Pushed my latest status thruflo/burn#1 -- getting a bunch more errors running tests. |
don't just use the existing electric stack
when there are never any shapes...
works now that we're ignoring migrations
Interesting idea. I'm going to work on the materialised shape stuff then come back to this. I think it would be possible to make some sandbox-aware client state that worked with a sandbox in shared mode but don't want to open that up in this pr which has gone on too long already. |
i.e. look at the type of the column when choosing between pg array and json format
so all requests are killed when the stack exits
thruflo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obviously would be nice to squish all warnings and connection errors in tests but let's merge and iterate if need be.
Fixes #31